import { HttpService } from './Service';
import type { CreateAxiosOptions } from '/#/http';
import { merge } from 'lodash-es';
import { transform } from './transform';
import { ContentTypeEnum } from '/@/enums/httpEnum';

import type { AxiosProgressEvent } from 'axios';

export function createHttp(options?: CreateAxiosOptions) {
  return new HttpService(
    merge(
      {
        headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED },
        authenticationScheme: '',
        transform,
        requestOptions: {
          // successMessageMode: 'message',
          errorMessageMode: 'message',
          joinTime: true,
        },
      },
      options || {},
    ),
  );
}

export const http = createHttp();
export { AxiosProgressEvent };
